const ENV = require('./env');

// 判断配置环境
let baseUrl = '';
switch (ENV.NODE_ENV) {
    case 'development':
        baseUrl = ENV.NODE_DEVELOP_URL;
        break;
    case 'production':
        baseUrl = ENV.NODE_BUILD_URL;
        break;
    case 'test':
        baseUrl = ENV.NODE_TEST_URL;
        break;
}

export default {
    // Global page headers: https://go.nuxtjs.dev/config-head
    head: {
        title: '黎三少',
        htmlAttrs: {
            lang: 'en'
        },
        meta: [
            { charset: 'utf-8' },
            { name: 'viewport', content: 'width=device-width, initial-scale=1' },
            { hid: 'description', name: 'description', content: '' },
            { name: 'format-detection', content: 'telephone=no' }
        ],
        link: [
            { rel: 'icon', type: 'image/x-icon', href: '/favicon.png' },
            { rel: 'stylesheet', href: 'https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css' },
        ],
        script: [
            { src: 'https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.5.1.min.js' },
            { src: 'https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js' }
        ]
    },

    // 修改端口
    server: {
        host: '127.0.0.1',
        port: 8802,
    },

    env: {
        baseUrl: baseUrl
    },

    axios: {
        proxy: true,       // 表示开启代理
        prefix: '/api',
    },
    proxy: {
        '/api': {
            target: baseUrl,
            pathRewrite: {
                '^/api': '/'
            }
        }
    },

    // Global CSS: https://go.nuxtjs.dev/config-css
    css: [
        'element-ui/lib/theme-chalk/index.css',
        'assets/css/animate/index.css',
        'assets/css/common/index.css',
        'assets/css/common/icon.css',
        'assets/css/emoji/index.css',
        'assets/css/emoji/emoji.css',
    ],

    loading: '@/components/loading.vue',

    // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
    plugins: [
        { src: '@/plugins/main', srr: true },
        { src: '@/plugins/component', srr: true },
        { src: '@/plugins/axios', srr: true },
        { src: '@/plugins/localStorage', ssr: false }
    ],

    // Auto import components: https://go.nuxtjs.dev/config-components
    components: true,

    // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
    buildModules: [
    ],

    // Modules: https://go.nuxtjs.dev/config-modules
    modules: [
        '@nuxtjs/axios',
        'cookie-universal-nuxt',
    ],

    router: {
        middleware: 'auth'
    },

    // Build Configuration: https://go.nuxtjs.dev/config-build
    build: {
    }
}
